import { defHttp } from '/@/utils/http/axios';
import { useMessage } from '/@/hooks/web/useMessage';

const { createConfirm } = useMessage();

enum Api {
  community = '/order/communityStatisticsList',
  communityExportXls = '/order/communityStatisticsList/exportXls',
  residential = '/order/residentialStatisticsList',
  residentialExportXls = '/order/residentialStatisticsList/exportXls',
  refund = '/order/refund',
  save = '/order/add',
  edit = '/order/edit',
  deleteOne = '/order/delete',
  deleteBatch = '/order/deleteBatch',
  importExcel = '/order/importExcel',
  exportXls = '/order/exportXls',
}
/**
 * 导出api
 * @param params
 */
export const getCommunityExportUrl = Api.communityExportXls;
export const getResidentialExportUrl = Api.residentialExportXls;
/**
 * 导入api
 */
export const getImportUrl = Api.importExcel;
/**
 * 列表接口
 * @param params
 */
export const communityList = (params) => defHttp.get({ url: Api.community, params });
export const residentialList = (params) => defHttp.get({ url: Api.residential, params });
/**
 * 退款接口
 * @param params
 */
export const refund = (params) => defHttp.get({ url: Api.refund, params });

/**
 * 删除单个
 */
export const deleteOne = (params, handleSuccess) => {
  return defHttp.delete({ url: Api.deleteOne, params }, { joinParamsToUrl: true }).then(() => {
    handleSuccess();
  });
};
/**
 * 批量删除
 * @param params
 */
export const batchDelete = (params, handleSuccess) => {
  createConfirm({
    iconType: 'warning',
    title: '确认删除',
    content: '是否删除选中数据',
    okText: '确认',
    cancelText: '取消',
    onOk: () => {
      return defHttp.delete({ url: Api.deleteBatch, data: params }, { joinParamsToUrl: true }).then(() => {
        handleSuccess();
      });
    },
  });
};
/**
 * 保存或者更新
 * @param params
 */
export const saveOrUpdate = (params, isUpdate) => {
  let url = isUpdate ? Api.edit : Api.save;
  return defHttp.post({ url: url, params });
};
